 
						** VT analysing core 5 ***
 
	clear
	version 15.1
	set seed 1234
	cd  "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (raw)/VTA/"

 
								*** VTLAG ***
	
	clear 
	use "core_vt_lag.dta"

	 
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="vt_lag"
		** 1.4.  %(significant != 0)  **
			count if var=="vt_lag" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="vt_lag" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="vt_lag" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="vt_lag" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="vt_lag" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		 
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="vt_lag"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="vt_lag"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(  2454516 , 10.96242) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="vt_lag", gen(cdf) equal
 		cumul beta_mean if var=="vt_lag", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 		
		global graph_options ", freq  xline(0, lcolor(red)) ytitle("") xtitle("") normal gap(25) ylabel(, angle(0) labsize(small))"
		
		hist coef if var=="vt_lag" $graph_options  title("Lagged DV, Coefficients") saving(h1c, replace)
		hist tstat if var=="vt_lag" $graph_options title("Lagged DV, T-statistic") saving(h1t, replace)
		

								*** COMP ***
	
	clear 
	use "core_comp.dta"

	 
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="comp"
		** 1.4.  %(significant != 0)  **
			count if var=="comp" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="comp" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="comp" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="comp" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="comp" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		 
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="comp"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="comp"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 2454272 ,  2.3815992) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="comp", gen(cdf) equal
 		cumul beta_mean if var=="comp", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 		
		global graph_options ", freq  xline(0, lcolor(red)) ytitle("") xtitle("") normal gap(25) ylabel(, angle(0) labsize(small))"
		
		hist coef if var=="comp" $graph_options  title("Compulsory voting, Coefficients") saving(h2c, replace)
		hist tstat if var=="comp" $graph_options title("Compulsory voting, T-statistic") saving(h2t, replace)
		

								*** PR ***
	clear
  
		use "core_pr.dta"

	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pr"
		** 1.4.  %(significant != 0)  **
			count if var=="pr" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pr" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pr" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pr" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pr" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		 	** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pr"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pr"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(2453693 ,.49463344) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pr", gen(cdf) equal
 		cumul beta_mean if var=="pr", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pr" $graph_options title("Proportional representation, Coefficients") saving(h3c, replace)
		hist tstat if var=="pr" $graph_options title("Proportional representation, T-statistic") saving(h3t, replace)
	
				

								*** GNI ***
	clear
 
		use "core_gni_ln_sl.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="gni_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="gni_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="gni_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="gni_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		 	** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="gni_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="gni_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 2454288  ,  .95848346) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="gni_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="gni_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, Coefficients") saving(h4c, replace)
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, T-statistics") saving(h4t, replace)
		

								*** POP ***
	clear 
		use "core_pop_ln_sl.dta"
		
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pop_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="pop_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pop_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pop_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		 	** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pop_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pop_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(2454288,  -.7072047) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pop_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="pop_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pop_ln_sl" $graph_options title("Population, Coefficients") saving(h5c, replace)
		hist coef if var=="pop_ln_sl" $graph_options title("Population, T-statistic") saving(h5t, replace)
		
		 graph combine  h2c.gph h2t.gph h3c.gph h3t.gph h4c.gph ///
						h4t.gph h5c.gph h5t.gph , title("VAPVT: Core 5")	///
						saving(VAPVT_core.gph, replace)
 		 
		erase  core_pop_ln_sl.dta
		erase  core_gni_ln_sl.dta
		erase core_vapvt_lag.dta 
		erase core_comp.dta
		erase  core_pr.dta
